using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQSZNFEHL
    {
        public DataRow Convert2QSZNFEHL(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQSZNFEHL(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["QSFMANDANT"] = " ".PadRight(2 ); 
         dwReturn["QSFAUFKRS"] = " ".PadRight(2 ); 
         dwReturn["QSFAUFLFD"] = " ".PadRight(6 ); 
         dwReturn["QSFAUFPOS"] = " ".PadRight(3 ); 
         dwReturn["QSFSZENNR"] = " ".PadRight(8 ); 
         dwReturn["QSFLSG"] = " ".PadRight(0 ); 
         dwReturn["QSFSTARTPUNKT"] = " ".PadRight(9 ); 
         dwReturn["QSFBRTVON"] = " ".PadRight(8 ); 
         dwReturn["QSFBRTBIS"] = " ".PadRight(8 ); 
         dwReturn["QSFLAUFNR"] = " ".PadRight(0 ); 
         dwReturn["QSFAENZL"] = " ".PadRight(0 ); 
         dwReturn["QSFAENB"] = " ".PadRight(8 ); 
         dwReturn["QSFAEND"] = " ".PadRight(0 ); 
         dwReturn["QSFNEUB"] = " ".PadRight(8 ); 
         dwReturn["QSFNEUD"] = " ".PadRight(0 ); 
         dwReturn["QSFSTKID"] = " ".PadRight(0 ); 
         dwReturn["QSFFKATALOG"] = " ".PadRight(3 ); 
         dwReturn["QSFFSCHL"] = " ".PadRight(3 ); 
         dwReturn["QSFEHLERSTART"] = " ".PadRight(9 ); 
         dwReturn["QSFEHLERENDE"] = " ".PadRight(9 ); 
         dwReturn["QSFFEHLERBRTV"] = " ".PadRight(8 ); 
         dwReturn["QSFFEHLERBRTB"] = " ".PadRight(8 ); 
         dwReturn["QSFSZNSTART"] = " ".PadRight(0 ); 
         dwReturn["QSFSZNENDE"] = " ".PadRight(0 ); 
         dwReturn["QSFBEZ"] = " ".PadRight(30 ); 
         dwReturn["QSFFART"] = " ".PadRight(2 ); 
         dwReturn["QSFVGUET"] = " ".PadRight(1 ); 
         dwReturn["QSFNETTO"] = " ".PadRight(1 ); 
         dwReturn["QSFMSCHNITT"] = " ".PadRight(1 ); 
         dwReturn["QSFDOMFKT"] = " ".PadRight(1 ); 
         dwReturn["QSFNAHT"] = " ".PadRight(1 ); 
         dwReturn["QSFTXTFEHL"] = " ".PadRight(1 ); 
         dwReturn["QSFREPARIERT"] = " ".PadRight(1 ); 
         dwReturn["QSFKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["QSFKST"] = " ".PadRight(0 ); 
         dwReturn["QSFSHADING"] = " ".PadRight(3 ); 
         dwReturn["QSFANZPKTFEHL"] = " ".PadRight(1 ); 
         dwReturn["QSFANZLNGFEHL"] = " ".PadRight(1 ); 
         dwReturn["QSFANZNAEHTE"] = " ".PadRight(1 ); 
         dwReturn["QSFANZFEHLPKT"] = " ".PadRight(0 ); 
         dwReturn["QSFPFVERGUET"] = " ".PadRight(0 ); 
         dwReturn["QSFLFVERGUET"] = " ".PadRight(0 ); 
         dwReturn["QSFVERGUETUNG"] = " ".PadRight(0 ); 
         dwReturn["QSFREPKOST"] = " ".PadRight(0 ); 
         dwReturn["QSFFILLER"] = " ".PadRight(55 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQSZNFEHL(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQSZNFEHL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQSZNFEHL(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQSZNFEHL(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQSZNFEHL(dwLocal, ITXDBVERSION);
            }
            UpdateQSZNFEHL(dwLocal);
        }
        public void InsertQSZNFEHL(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QSZNFEHL(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQSZNFEHL(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QSZNFEHL WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QSZNFEHL  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QSZNFEHL";
            Return = Result;
            return Return;
        }
        public void DeleteQSZNFEHL(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QSZNFEHL   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQSZNFEHL(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QSZNFEHL SET "
                    +"QSFMANDANT= :QSFMANDANT,"
                    +"QSFAUFKRS= :QSFAUFKRS,"
                    +"QSFAUFLFD= :QSFAUFLFD,"
                    +"QSFAUFPOS= :QSFAUFPOS,"
                    +"QSFSZENNR= :QSFSZENNR,"
                    +"QSFLSG= :QSFLSG,"
                    +"QSFSTARTPUNKT= :QSFSTARTPUNKT,"
                    +"QSFBRTVON= :QSFBRTVON,"
                    +"QSFBRTBIS= :QSFBRTBIS,"
                    +"QSFLAUFNR= :QSFLAUFNR,"
                    +"QSFAENZL= :QSFAENZL,"
                    +"QSFAENB= :QSFAENB,"
                    +"QSFAEND= :QSFAEND,"
                    +"QSFNEUB= :QSFNEUB,"
                    +"QSFNEUD= :QSFNEUD,"
                    +"QSFSTKID= :QSFSTKID,"
                    +"QSFFKATALOG= :QSFFKATALOG,"
                    +"QSFFSCHL= :QSFFSCHL,"
                    +"QSFEHLERSTART= :QSFEHLERSTART,"
                    +"QSFEHLERENDE= :QSFEHLERENDE,"
                    +"QSFFEHLERBRTV= :QSFFEHLERBRTV,"
                    +"QSFFEHLERBRTB= :QSFFEHLERBRTB,"
                    +"QSFSZNSTART= :QSFSZNSTART,"
                    +"QSFSZNENDE= :QSFSZNENDE,"
                    +"QSFBEZ= :QSFBEZ,"
                    +"QSFFART= :QSFFART,"
                    +"QSFVGUET= :QSFVGUET,"
                    +"QSFNETTO= :QSFNETTO,"
                    +"QSFMSCHNITT= :QSFMSCHNITT,"
                    +"QSFDOMFKT= :QSFDOMFKT,"
                    +"QSFNAHT= :QSFNAHT,"
                    +"QSFTXTFEHL= :QSFTXTFEHL,"
                    +"QSFREPARIERT= :QSFREPARIERT,"
                    +"QSFKSTKRS= :QSFKSTKRS,"
                    +"QSFKST= :QSFKST,"
                    +"QSFSHADING= :QSFSHADING,"
                    +"QSFANZPKTFEHL= :QSFANZPKTFEHL,"
                    +"QSFANZLNGFEHL= :QSFANZLNGFEHL,"
                    +"QSFANZNAEHTE= :QSFANZNAEHTE,"
                    +"QSFANZFEHLPKT= :QSFANZFEHLPKT,"
                    +"QSFPFVERGUET= :QSFPFVERGUET,"
                    +"QSFLFVERGUET= :QSFLFVERGUET,"
                    +"QSFVERGUETUNG= :QSFVERGUETUNG,"
                    +"QSFREPKOST= :QSFREPKOST,"
                    +"QSFFILLER= :QSFFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("QSFMANDANT", OracleType.NVarChar).Value = dwData["QSFMANDANT"].ToString(); 
          or1.Parameters.Add("QSFAUFKRS", OracleType.NVarChar).Value = dwData["QSFAUFKRS"].ToString(); 
          or1.Parameters.Add("QSFAUFLFD", OracleType.NVarChar).Value = dwData["QSFAUFLFD"].ToString(); 
          or1.Parameters.Add("QSFAUFPOS", OracleType.NVarChar).Value = dwData["QSFAUFPOS"].ToString(); 
          or1.Parameters.Add("QSFSZENNR", OracleType.NVarChar).Value = dwData["QSFSZENNR"].ToString(); 
          or1.Parameters.Add("QSFLSG", OracleType.NVarChar).Value = dwData["QSFLSG"].ToString(); 
          or1.Parameters.Add("QSFSTARTPUNKT", OracleType.NVarChar).Value = dwData["QSFSTARTPUNKT"].ToString(); 
          or1.Parameters.Add("QSFBRTVON", OracleType.NVarChar).Value = dwData["QSFBRTVON"].ToString(); 
          or1.Parameters.Add("QSFBRTBIS", OracleType.NVarChar).Value = dwData["QSFBRTBIS"].ToString(); 
          or1.Parameters.Add("QSFLAUFNR", OracleType.NVarChar).Value = dwData["QSFLAUFNR"].ToString(); 
          or1.Parameters.Add("QSFAENZL", OracleType.NVarChar).Value = dwData["QSFAENZL"].ToString(); 
          or1.Parameters.Add("QSFAENB", OracleType.NVarChar).Value = dwData["QSFAENB"].ToString(); 
          or1.Parameters.Add("QSFAEND", OracleType.NVarChar).Value = dwData["QSFAEND"].ToString(); 
          or1.Parameters.Add("QSFNEUB", OracleType.NVarChar).Value = dwData["QSFNEUB"].ToString(); 
          or1.Parameters.Add("QSFNEUD", OracleType.NVarChar).Value = dwData["QSFNEUD"].ToString(); 
          or1.Parameters.Add("QSFSTKID", OracleType.NVarChar).Value = dwData["QSFSTKID"].ToString(); 
          or1.Parameters.Add("QSFFKATALOG", OracleType.NVarChar).Value = dwData["QSFFKATALOG"].ToString(); 
          or1.Parameters.Add("QSFFSCHL", OracleType.NVarChar).Value = dwData["QSFFSCHL"].ToString(); 
          or1.Parameters.Add("QSFEHLERSTART", OracleType.NVarChar).Value = dwData["QSFEHLERSTART"].ToString(); 
          or1.Parameters.Add("QSFEHLERENDE", OracleType.NVarChar).Value = dwData["QSFEHLERENDE"].ToString(); 
          or1.Parameters.Add("QSFFEHLERBRTV", OracleType.NVarChar).Value = dwData["QSFFEHLERBRTV"].ToString(); 
          or1.Parameters.Add("QSFFEHLERBRTB", OracleType.NVarChar).Value = dwData["QSFFEHLERBRTB"].ToString(); 
          or1.Parameters.Add("QSFSZNSTART", OracleType.NVarChar).Value = dwData["QSFSZNSTART"].ToString(); 
          or1.Parameters.Add("QSFSZNENDE", OracleType.NVarChar).Value = dwData["QSFSZNENDE"].ToString(); 
          or1.Parameters.Add("QSFBEZ", OracleType.NVarChar).Value = dwData["QSFBEZ"].ToString(); 
          or1.Parameters.Add("QSFFART", OracleType.NVarChar).Value = dwData["QSFFART"].ToString(); 
          or1.Parameters.Add("QSFVGUET", OracleType.NVarChar).Value = dwData["QSFVGUET"].ToString(); 
          or1.Parameters.Add("QSFNETTO", OracleType.NVarChar).Value = dwData["QSFNETTO"].ToString(); 
          or1.Parameters.Add("QSFMSCHNITT", OracleType.NVarChar).Value = dwData["QSFMSCHNITT"].ToString(); 
          or1.Parameters.Add("QSFDOMFKT", OracleType.NVarChar).Value = dwData["QSFDOMFKT"].ToString(); 
          or1.Parameters.Add("QSFNAHT", OracleType.NVarChar).Value = dwData["QSFNAHT"].ToString(); 
          or1.Parameters.Add("QSFTXTFEHL", OracleType.NVarChar).Value = dwData["QSFTXTFEHL"].ToString(); 
          or1.Parameters.Add("QSFREPARIERT", OracleType.NVarChar).Value = dwData["QSFREPARIERT"].ToString(); 
          or1.Parameters.Add("QSFKSTKRS", OracleType.NVarChar).Value = dwData["QSFKSTKRS"].ToString(); 
          or1.Parameters.Add("QSFKST", OracleType.NVarChar).Value = dwData["QSFKST"].ToString(); 
          or1.Parameters.Add("QSFSHADING", OracleType.NVarChar).Value = dwData["QSFSHADING"].ToString(); 
          or1.Parameters.Add("QSFANZPKTFEHL", OracleType.NVarChar).Value = dwData["QSFANZPKTFEHL"].ToString(); 
          or1.Parameters.Add("QSFANZLNGFEHL", OracleType.NVarChar).Value = dwData["QSFANZLNGFEHL"].ToString(); 
          or1.Parameters.Add("QSFANZNAEHTE", OracleType.NVarChar).Value = dwData["QSFANZNAEHTE"].ToString(); 
          or1.Parameters.Add("QSFANZFEHLPKT", OracleType.NVarChar).Value = dwData["QSFANZFEHLPKT"].ToString(); 
          or1.Parameters.Add("QSFPFVERGUET", OracleType.NVarChar).Value = dwData["QSFPFVERGUET"].ToString(); 
          or1.Parameters.Add("QSFLFVERGUET", OracleType.NVarChar).Value = dwData["QSFLFVERGUET"].ToString(); 
          or1.Parameters.Add("QSFVERGUETUNG", OracleType.NVarChar).Value = dwData["QSFVERGUETUNG"].ToString(); 
          or1.Parameters.Add("QSFREPKOST", OracleType.NVarChar).Value = dwData["QSFREPKOST"].ToString(); 
          or1.Parameters.Add("QSFFILLER", OracleType.NVarChar).Value = dwData["QSFFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
